package im.xz.cn.xiacore.events;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class join implements Listener {
    @EventHandler
    public void qwq(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        ItemStack menu = new ItemStack(Material.CLOCK);
        ItemMeta meta = menu.getItemMeta();
        try {
            if (player.getWorld().getName().equals("lobby")) {
                World lobby = event.getPlayer().getServer().getWorld("lobby");
                Location spawn = new Location(lobby,-64,71,-46);
                event.getPlayer().teleport(spawn);
                player.sendMessage(ChatColor.GREEN + "欢迎进入繁星梦Minecraft服务器，你可输入指令/menu打开菜单使用更多功能!");
                player.sendMessage(ChatColor.GRAY + "使用/helppage指令查看帮助文档。");
            }else if (player.getWorld().getName().equals("normal")) {
                player.sendMessage(ChatColor.GRAY + "此服务器已加载日历时节，使用/when以取得时间");
                player.sendMessage(ChatColor.GRAY + "此服务器已加载玩家地皮，使用/gethome以取得一块，/backhome以回到地皮");
            }
        }catch (NullPointerException ingore) {

        }
        meta.setDisplayName(ChatColor.LIGHT_PURPLE + "游戏菜单");
        ArrayList<String> lore = new ArrayList<>();
        lore.add(ChatColor.WHITE + "使用以打开游戏菜单！");
        lore.add(ChatColor.WHITE + "使用指令/menu也可以哦");
        meta.setLore(lore);
        menu.setItemMeta(meta);
        try {
            if (player.getInventory().contains(menu)) {

            }else {
                player.getInventory().addItem(menu);
            }
        }catch (NullPointerException ignore) {
        }
    }
}